package com.lanou3g.test.stream;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * Created by dllo on 18/4/14.
 */
public class Main {
    public static void main(String[] args) {
        File file = new File("out,txt");
        if (!file.exists()) {
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        FileOutputStream fos = null;
        try {
          fos = new FileOutputStream(file);
            String data = "Hello World";
            //向文件中 写数据
            // 只能写 字节类型的数据
            //字符串也需要转换成字节数组
            fos.write(data.getBytes());

        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if(fos!=null){
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
